// pages/volua/volua.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    VAILD: '', //判断是否领取
    USER_COUPON_PHONE: '', //领奖人电话
    COUPON_ID: '', //奖券ID
    jiangsj: [], //奖券参数
    wcwc: [],
    city: '',
    kajuan: '',
    dangx: '', //单个信息
    NEW_VAILD: '',
    flag: true, //设置节流
    // Getphone: false,



    wang_d: '', //地点
    city: [], //市
    district: [], //区
    business: '', //网点
    shi_k: true,
    qu_k: true,
    wang_k: true,
    tishi: true,

    shiquxuan: true,

    L2name: '',
    L3name: '',
    L4name: '',

    L4code: '',
  },


  xiang_lq() {
    wx.showModal({
      title: '温馨提示',
      content: '您已领取,请勿重复领取',
      success: function (res) {
        if (res.confirm) { //这里是点击了确定以后

        } else { //这里是点击了取消以后
          console.log('用户点击取消')
        }
      }
    })
  },

  xiang_qlq() {
    // console.log('2222',e.currentTarget);

    wx.request({
      url: app.globalData.interface+'/crossVersionOne/API2_2105_NewCustomerGiftsSendCoupon',
      method: 'post',
      data: {
        // COUPON_ID: this.data.dangx.COUPON_ID,

        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
        USER_ASSETS_ID: this.data.dangx.USER_ASSETS_ID,
        USER_COUPON_PHONE: this.data.dangx.USER_COUPON_PHONE,
        USER_COUPON_ID: this.data.dangx.USER_COUPON_ID,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);

        let that = this


        wx.showModal({
          title: '温馨提示',
          content: res.data.data,
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后
              console.log('用户点击确定')
              that.quanliebiao()
            } else { //这里是点击了取消以后
              console.log('用户点击取消')
              that.quanliebiao()
            }
          }
        })
      }
    })

  },





  gotype(e) {


    if (this.data.flag) {

      this.data.flag = false


      console.log('e.currentTarget.dataset.item', e.currentTarget.dataset.item);
      if (e.currentTarget.dataset.item.VALID == 1) {
        wx.showModal({
          title: '温馨提示',
          content: '请去线下网点激活',
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后

            } else { //这里是点击了取消以后
              console.log('用户点击取消')
            }
          }
        })
      } else if (e.currentTarget.dataset.item.VALID == 2) {

        console.log('@@@@@@@@@@@@@@@@@@@@', e.currentTarget);

        wx.showModal({
          title: '温馨提示',
          content: '请去线下网点激活',
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后

            } else { //这里是点击了取消以后
              console.log('用户点击取消')
            }
          }
        })




      } else if (e.currentTarget.dataset.item.VALID == 3) {

        console.log(e.currentTarget.dataset.item);

        this.setData({
          dangx: e.currentTarget.dataset.item
        })

        this.xiang_qlq()

      } else if (e.currentTarget.dataset.item.VALID == 4) {
        wx.showModal({
          title: '温馨提示',
          content: '已经领过',
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后

            } else { //这里是点击了取消以后
              console.log('用户点击取消')
            }
          }
        })

      }


      setTimeout(() => {
        this.data.flag = true
      }, 3000)
    }

  },



















  quanliebiao() {

    wx.request({
      url: app.globalData.interface+'/crossVersionOne/API2_2101_YueYueXiangSelect',
      method: 'post',
      data: {

        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data);

        const imgarr = {
          1: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/xiantoupiao871.png', // 未激活
          2: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/xiantoupiao871.png', // 未激活
          3: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/xiantoupiao875.png', // 未领取
          4: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/guapai012.png' // 已领取
        }




        if (res.data.result != 'success') {
          console.log(res.data.code);

          if (res.data.code == '0') {
            wx.showModal({
              title: '温馨提示',
              content: '您未注册，请先注册！',
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后
                  console.log('用户点击确定')
                  wx.navigateTo({
                    url: '../../pages/newquanyizhuce/newquanyizhuce',
                  })
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                  wx.navigateTo({
                    url: '../../pages/newquanyizhuce/newquanyizhuce',
                  })
                }
              }
            })

          } else if (res.data.code == '1') {


            wx.showModal({
              title: '温馨提示',
              content: '内部错误！请稍后再试！',
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后
                  console.log('用户点击确定')
                  wx.navigateBack({
                    delta: 1,
                  })
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              }
            })

          } else if (res.data.code == '2') {



            wx.showModal({
              title: '温馨提示',
              content: '您已不是新用户,点击跳转星级权益！',
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后
                  console.log('用户点击确定')
                  wx.switchTab({
                    url: '../../pages/newquanyijinrumokuai/newquanyijinrumokuai',
                  })
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                  wx.switchTab({
                    url: '../../pages/newquanyijinrumokuai/newquanyijinrumokuai',
                  })
                }
              }
            })

          } else if (res.data.code == '3') {

            this.setData({
              shiquxuan: false,
            })
            console.log('出现');

          }

        } else {


          const list = res.data.data.map((item, index) => {
            return {
              ...item,
              ISIMG: imgarr[item.VALID]
            }
          })


          const list2 = res.data.data2.map((item, index) => {
            return {
              ...item,
              ISIMG: imgarr[item.VALID]
            }
          })

          console.log('www', list);




          console.log('@@@', res.data.code);
          this.setData({
            // jiangsj: res.data.data
            jiangsj: list,
            jiangsj2: list2
          })
        }
      }
    })
  },















  region() {
    wx.request({
      url: app.globalData.interface+'/newVersion/API_2029_outletPush',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.data);
        this.setData({
          city: res.data.data,
        })

      }
    })
  },


  but_shi() {
    this.setData({
      shi_k: false,

    })

    this.setData({
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,
    });

    console.log(this.data.session_key);
  },

  but_xian() {
    if (this.data.L2code == '') {
      wx.showToast({
        title: '请先选择市',
        icon: 'error',
        duration: 2000
      })
    } else {
      this.setData({
        qu_k: false
      })
    }
  },

  but_w() {

    if (this.data.L2code == '') {
      wx.showToast({
        title: '请先选择区',
        icon: 'error',
        duration: 2000
      })
    } else {
      this.setData({
        wang_k: false
      })
    }

  },


  //市
  buttn_c(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.district);
    console.log(e.currentTarget.dataset.item.L2code);
    this.setData({
      district: e.currentTarget.dataset.item.district,
      L2code: e.currentTarget.dataset.item.L2code,
      L2name: e.currentTarget.dataset.item.L2name,
      shi_k: true,
      L3name: '',
      L4name: '',

    })

  },

  buttn_x(e) {
    console.log(e);


    this.setData({
      L3code: e.currentTarget.dataset.item.L3code,
      L3name: e.currentTarget.dataset.item.L3name,
      qu_k: true,
      L4name: '',
    })
    this.Outlets()

  },


  buttn_w(e) {
    console.log(e);
    this.setData({
      L4name: e.currentTarget.dataset.item.L4name,
      L4code: e.currentTarget.dataset.item.L4code,
      EMPLOYEE_ID: e.currentTarget.dataset.item.EMPLOYEE_ID,

      wang_k: true
    })





  },

  //网点
  Outlets() {
    wx.request({
      url: app.globalData.interface+'/newVersion/API_2027_outletList',
      method: 'POST',
      data: {
        L2code: this.data.L2code,
        L3code: this.data.L3code
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        console.log(res.data.data);
        this.setData({
          business: res.data.data
        })

      }
    })
  },






  //网点
  bouut() {
    wx.request({
      url: app.globalData.interface+'/crossVersionOne/API2_2131_UpdateUserBrch',
      method: 'POST',
      data: {

        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
        L4code: this.data.L4code
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);

        wx.showModal({
          title: '温馨提示',
          content: res.data.data,
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后
              console.log('用户点击确定')
              wx.navigateBack({
                delta: 1,
              })
            } else { //这里是点击了取消以后
              console.log('用户点击取消')
              wx.navigateBack({
                delta: 1,
              })
            }
          }
        })


      }
    })
  },





















  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {




    setTimeout(() => {
      this.setData({

        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        openid: app.globalData.openid,
        session_key: app.globalData.session_key,


      })
      this.quanliebiao()

    }, 800)


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    this.region()


  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})